import request from '@/utils/request'

const User_Api = '/admin/acl/user'

export default {
  //获取用户列表数据
  getUserList(page, limit, searchObj) {
    return request({
      url: `${User_Api}/${page}/${limit}`,
      method: 'get',
      params: searchObj
    })
  },

  //根据ID删除用户
  removeById(id) {
    return request({
      url: `${User_Api}/remove/${id}`,
      method: 'delete'
    })
  },

  //添加或更新新用户
  addOrUpdateUser(user){
    if (user.id) {
      return request({
        url: `${User_Api}/update`,
        method: 'put',
        data: user
      })
    } else {
      //如果没有id  就添加一个新用户
      return request({
        url: `${User_Api}/save`,
        method: 'post',
        data: user
      })
    }
  },

  //获取某个用户的所有角色
  getRoles(userId) {
    return request({
      url: `${User_Api}/toAssign/${userId}`,
      method: 'get'
    })
  },

  //给某个用户分配角色
  reqDoAssign(userId, roleId) {
    return request({
      url: `${User_Api}/doAssign`,
      method: 'post',
      params: {
        userId,
        roleId
      }
    })
  },
}